<!--
 * @FilePath     : /jquery/demo/101-16.html
 * @Description  : :first-of-type
 * @Date         : 2025-03-27 10:47:04
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-03-27 13:42:10
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <h2>jq_page</h2>
    <div id="n1">
      <div id="n2" class="abc">
        <label id="n3">label1</label>
        <span id="n4">span1</span>
        <span id="n5" class="abc">span2</span>
        <span id="n6">span3</span>
      </div>
      <div id="n7">
        <span id="n8" class="abc">span1</span>
        <span id="n9">span2</span>
      </div>
    </div>

    <script src="/library/jquery.min.js"></script>
    <script src="/common/common.js"></script>
    <script>
      console.log(1, $('span:first-of-type'))
      /*
      结果：
      [
        <span id="n4">span1</span>,
        <span id="n8" class="abc">span1</span>
      ]

      #n4, #n5, #n6 是同一个父元素，筛选出 #n4；
      #n8, #n9 是同一个父元素，筛选出 #n8；
      */

      console.log(2, $('.abc:first-of-type'))
      /*
      结果：
      [
        <div id="n2" class="abc">​…​</div>​,
        <span id="n8" class="abc">​…​</span>​
      ]

      #n2.abc 父元素下，筛选出自己；
      #n5.abc 父元素是 #n2.abc，不是 #n2跳过；
      #n8.abc 父元素是 #n7，筛选出自己；
      */
    </script>

    <script>
      console.log(3, $('span:last-of-type'))
      /*
      [ #n6, #n9 ]
      */

      console.log(4, $('.abc:last-of-type'))
      // []
    </script>
  </body>
</html>
